var acidacid
Page({
  data: {
    statusBarHeight:0,
    HeaderBar:0,
    biaozhi:'',wfzarr:[],
    message:[
    {
      id:0,
      img:'../image/tx.png',
      name:'yy',
    },
    {
      id:1,
      img:'../image/tx.png',
      name:'yy',

    },
    {
      id:2,
      img:'../image/tx.png',
      name:'yy'

    }
    ],
    arr:[],
    tiao:'↓',
    isAgree:'0',
    activityId:''
  },
//跳转到未分组里面
  tiao:function(e){
    var me = this;
    var query = wx.createSelectorQuery().in(me);
      if(me.data.tiao=='↓'){
        query.selectViewport().scrollOffset()
        //#comm 跳转到指定id位置
        query.select(".uo").boundingClientRect();
        query.exec(function (res) {
          var miss = res[0].scrollTop + res[1].top - 10;
          wx.pageScrollTo({
            scrollTop: miss,
            duration: 300
          });
        });
        me.setData({
          tiao:'↑'
        })
      }else if(me.data.tiao=='↑'){
        query.selectViewport().scrollOffset()
        //#comm 跳转到顶部
        query.select(".nav").boundingClientRect();
        query.exec(function (res) {
          var miss =res[1].top;
          wx.pageScrollTo({
            scrollTop: miss,
            duration: 300
          });
        });
        me.setData({
          tiao:'↓'
        })
      }else{
       
      }
  },
//教练点击开始后进行的操作，开始或者不开始
  start:function(){
    var that=this;
    var res=that.data.arr
    console.log(that.data.isAgree)
    // for(var i=0;i<res.length;i++){
    // for(var j=0;j<res[i].Details.length;j++){
      // console.log(res[i].Details[j].IsLock)
      // if(res[i].Details[j].IsLock==0){
      //   console.log('未准备的玩家')
      //   that.setData({
      //     isAgree:'1'
      //   })
      //   wx.showToast({
      //     title: '还有人未准备好',
      //   })
      // }else{
        // wx.navigateTo({
        //   url: '../../pages/home/home',
        // })
        that.setData({
          isAgree:'1'
        })
        wx.request({
          url: 'https://www.juquduo.com/juquduo/gaming/coach_confirmed',
          data:{
            activityId:acidacid
          },
          success(res){
            console.log(res.data)
            that.setData({
              activityId:res.data
            })
          }
        })
        console.log('已准备好')
  },
  onLoad: function (options) {

    let scene = options.scene;
    var tzid = options.id
    // let scene=decodeURIComponent(options.scene);
    if(scene){
      acidacid=scene.split(".")[0];
      console.log('扫描小程序码进入页面',acidacid)
    }else if(tzid){
      //页面跳转
      acidacid = options.id
      console.log('扫描二维码或跳转进入页面',acidacid)
    }

    if(acidacid==undefined){
      console.log('没有活动id，改为264')
      acidacid = 271
    }
    var that=this;
    //所有玩家信息，已分组
    wx.request({
      url:"https://www.juquduo.com/juquduo/join_activity/players",
      data:{
        isAgree:that.data.isAgree,
        activityId:acidacid
      },
      success(res){
        console.log("请求成功",res)
        var res=res.data.Info;
        for(var i=0;i<res.length;i++){
          // console.log(res[i].Details)
          //将字符串转化为数组后并替换数据里面的字符串
          var data=JSON.parse(res[i].Details)
          res[i].Details=data
        }
        that.setData({
          arr:res
        })
      }
    })
    //获取后台数据，本组玩家
    wx.request({
      url:"https://www.juquduo.com/juquduo/activity/group_players",
      data:{
        activityId:acidacid,
        lockType:1,
      },
      header:{
        'Content-type': 'application/json'
      },
      success(res){
        // console.log(that.data.lockType)
        that.setData({
          wfzarr:res.data,
        })
        console.log('本组玩家',res.data)
      }
    })
    //获取并发送activityedId
    wx.request({
      url: 'https://www.juquduo.com/juquduo/activity/lock_group',
      data:{
        activityId:that.data.activityId
      },
      success(res){
        console.log(res.data)
        that.setData({
          activityId:res.data
        })
      }
    })
  }
})